<?php
namespace app\com\simtoon\publicmodels;
use Yii;
use yii\web\Link;
use yii\helpers\Url;
use yii\base\Exception;
use app\com\simtoon\log\LogUtils;
use app\com\simtoon\comm\Common;
use yii\data\SqlDataProvider;
use app\com\simtoon\utils\CacheUtils;
use app\com\simtoon\base\BaseModel;
use yii\data\ActiveDataProvider;

class GoodInfor extends BaseModel{
	 //查询位置、型号、批次、品类、尺寸、体积   / 厂商、联系人、电话  / 代理商、联系人、电话
        public function BasicInfor($post){
        	 if(empty($post['splitid'])){
	        	 $querySql="SELECT f.goodname,f.batchnumber,f.volume,f.versionnumber,f.packageleng,f.packagewidth,f.packageheight,t.typeName,ss.stock_name,pp.ware_house_name,pp.height,pp.layer_num,
	        	 v.vendername,v.vendercharge,v.venderphone, gg.agentname,gg.agentcharge,gg.agentphone from t_goods_infodetail f  left join t_sys_type t on f.typeid=t.id left join t_sys_ware_position pp on
	        	  f.locationid=pp.id left join t_sys_stockhouse ss on pp.userId=ss.stock_id  LEFT join t_goods_arrivelist aa on f.dealline=aa.dealline left join t_sys_vender v on aa.venderid=v.id left join 
	        	    t_goods_agent gg on aa.agentid=gg.agentid where f.goodid='".$post['id']."' and f.dealline='".$post['orderid']."'";
        	 }else{
        	 	$querySql="SELECT sp.splitcontent as goodname,f.batchnumber,f.volume,f.versionnumber,sp.packageleng,sp.packagewidth,sp.packageheight,ty.typeName,ss.stock_name,pp.ware_house_name,
        	 		pp.height,pp.layer_num, v.vendername,v.vendercharge,v.venderphone, gg.agentname,gg.agentcharge,gg.agentphone from t_goods_splitsub sp left join  t_goods_infodetail f ON
				sp.goodid=f.goodid and sp.dealline=f.dealline left join t_sys_type t on f.typeid=t.id left join t_sys_ware_position pp on  sp.locationid=pp.id left join t_sys_stockhouse ss on 
				pp.userId=ss.stock_id  LEFT join t_goods_arrivelist aa on f.dealline=aa.dealline left join t_sys_vender v on aa.venderid=v.id left join  t_goods_agent gg on aa.agentid=gg.agentid 
				left join t_sys_type ty on sp.goodtype=ty.id where sp.id='".$post['splitid']."'";
        	 }
  		$adp = array();
		try {
			LogUtils::info("Query sql={" . $querySql . "}", __METHOD__);
			$adp = new SqlDataProvider([
				'sql' => $querySql
				]);
		} catch (Exception $e) {
			LogUtils::error($e->getMessage(), __METHOD__);
			return $adp;
		} 
		return $adp;
        }
        //查询入库的时间、操作人员
         public function warehousing($post){
           	$querySql="SELECT aa.*,bb.*,if(cc.timeb is null,cc.timea,cc.timeb)as time from
				(SELECT u.pet_name as gongname,u.phone_number as gongphone from t_goods_arrivelist a  LEFT join t_sys_user u on a.handlebody_kgong=u.uuid  where a.dealline='".$post['orderid']."')aa,
				(SELECT u.pet_name as guanname,u.phone_number as guanphone from t_goods_arrivelist a  LEFT join t_sys_user u on a.handlebody_kguan=u.uuid  where a.dealline='".$post['orderid']."')bb,
				(SELECT  g.*,pp.* from	
						(SELECT instoretime as timea  from t_good_ingoods  where dealline='".$post['orderid']."' and dnumber='".$post['id']."')g,
						(select instoretime as timeb from t_good_inpackage  where goodidc='1' and dealline='".$post['orderid']."' )pp   
				 ) cc";
  		$adp = array();
		try {
			LogUtils::info("Query sql={" . $querySql . "}", __METHOD__);
			$adp = new SqlDataProvider([
				'sql' => $querySql
				]);
		} catch (Exception $e) {
			LogUtils::error($e->getMessage(), __METHOD__);
			return $adp;
		} 
		return $adp;
        }
        //查询异常原因、维修工
        public function abnormality($post){
           	$querySql="SELECT s.remarkinfo,u.pet_name,u.phone_number,a.state from t_sys_isquote s left join t_sys_abdeallist a on s.abdealline=a.abdealline left join t_sys_donelist d on s.abdealline=d.abdealline
           	                     left join t_sys_user u on d.doneuuid=u.uuid where a.goodid='".$post['id']."' and a.dealline='".$post['orderid']."'";
  		$adp = array();
		try {
			LogUtils::info("Query sql={" . $querySql . "}", __METHOD__);
			$adp = new SqlDataProvider([
				'sql' => $querySql
				]);
		} catch (Exception $e) {
			LogUtils::error($e->getMessage(), __METHOD__);
			return $adp;
		} 
		return $adp;
        }
}
?>